<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page import="com.mvc.security.model.Menu"%>
<%@ include file="/pages/common/header.jsp"%>
</head>
<c:choose>
    <c:when test="${type=='3'}">
        <c:set value="财务权限管理" var="title"/> 
    </c:when>
    <c:otherwise>
        <c:set value="权限管理" var="title"/> 
    </c:otherwise>
</c:choose>
<body>
    <div class="contentBody contentBodyborder">
        <div class="tab-pane" id="tabPane">
            <div id="message"><%=message%></div>
            <div class="tab-page" id="tabPage1">
                <h1 class="tab">${title}</h1>
                <div class="contentborder tableForm">
                    <jdf:form bean="entity" scope="request">
                        <form action="<%=dynamicDomain%>/userCompanyPrivilege/save/${type}" method="post" onsubmit="prepare();" id="userCompany">
                            <input type="hidden" name="companyIds" id="companyIds">
                            <input type="hidden" name="userIds" id="userIds">
                            <table class="inputTable">
                                <c:forEach varStatus="num" var="item" items="${companies}">
                                <tr>
                                    <td class="label cancelBorderLeft" style="width: 30%">
                                      <label for="title">${item.name }：</label>
                                    </td>
                                    <td class="content" colspan="3">
	                                    <table name="company" id="${item.objectId}">
								            <tr>
								                <c:set var="_count" value="0" />
								                <c:forEach varStatus="num" var="item0" items="${users}">
								                        <c:set var="_count" value="${_count + 1}" />
								                        <c:set var="_check" value="" />
								                         <c:forEach varStatus="num" var="item1" items="${selected}">
								                            <c:if test="${item1.companyId ==item.objectId && item1.userId ==item0.objectId}">
								                                <c:set var="_check" value="checked" />
								                            </c:if>
								                         </c:forEach>
								                        <td>&nbsp;<input type="checkbox" value="${item0.objectId}" id="u_${item.objectId}_${item0.objectId}" name="users"  ${_check} style="vertical-align: middle;"></td>
								                        <td>&nbsp;<label for="u_${item.objectId}_${item0.objectId}" >${item0.userName}</label></td>
								                    <c:if test="${_count%5==0&&_count!=0 }">
								            </tr>
								            <tr>
								                </c:if>
								                </c:forEach>
								        </table>
                                    </td>
                                </tr>
                                </c:forEach>
                                <tr>
                                    <td class="bottomLabel" nowrap colspan="4">
                                        <div class="right">
                                            <button type="submit">提交</button>
                                        </div>
                                    </td>
                                </tr>
                                
                            </table>
                        </form>
                    </jdf:form>
                </div>
            </div>
        </div>
        <script type="text/javascript">
        function prepare() {
            var company = $('[name="company"]');
            var userIds = "";
            var companyIds = "";
            for(i=0;i<company.length;i++){
                var companyId = $(company[i]).attr("id");
            	companyIds += companyId + ";";
            	var userId = "";
            	$('[name="users"]',company[i]).each(function(){
                    if($(this).attr("checked")){
                    	userId += $(this).val() + ",";
                    }
                });
            	userIds += userId + ";";
            }
            $("#companyIds").val(companyIds);
            $("#userIds").val(userIds);
        }
        </script>
    </div>
</body>
</html>